import { defineStore } from 'pinia'
import { store } from '/@/store'
import type { AxiosResponse } from 'axios'
import type { Res } from '/@/tool/Res'
import type { Param } from '/@/tool/Param'

import coreToolService from '/@/api/cn/core/tool/coreToolService'

import type { LoginAO } from '/@/model/cn/core/tool/ao/LoginAO'
import type { LoginVO } from '/@/model/cn/core/tool/vo/LoginVO'

interface CoreToolState {
}

export const useCoreToolStore = defineStore({
  id: 'coreTool',
  state: (): CoreToolState => ({
  }),
  getters: {
  },
  actions: {
    login(param: Param<LoginAO>): Promise<Res<LoginVO>> {
      return new Promise<Res<LoginVO>>((resolve, reject) => {
        coreToolService.login(param).then((res: AxiosResponse<Res<LoginVO>>) => {
          resolve(res.data)
        }).catch(err => {
          reject(err)
        })
      })
    },
  },
})

export function useCoreToolStoreWithout() {
  return useCoreToolStore(store)
}
